using System;

namespace OracleInternal.SqlAndPlsqlParser
{
	public class FlexibleSizeLongArray
	{
		public const int c_vGapSize = 8;

		public long[] m_vArray;

		public int m_vContentSize;

		public FlexibleSizeLongArray(int capacity)
		{
			m_vArray = new long[capacity];
		}

		public FlexibleSizeLongArray(long[] array)
		{
			if (array == null)
			{
				m_vArray = new long[8];
				return;
			}
			m_vArray = array;
			m_vContentSize = array.Length;
		}

		public FlexibleSizeLongArray(FlexibleSizeLongArray fArray)
		{
			if (fArray == null)
			{
				m_vArray = new long[8];
				return;
			}
			m_vContentSize = fArray.m_vContentSize;
			m_vArray = new long[m_vContentSize + 8];
			long[] vArray = fArray.m_vArray;
			for (int i = 0; i < m_vContentSize; i++)
			{
				m_vArray[i] = vArray[i];
			}
		}

		public static FlexibleSizeLongArray Merge(FlexibleSizeLongArray x, FlexibleSizeLongArray y)
		{
			if (x == null)
			{
				return new FlexibleSizeLongArray(y);
			}
			if (y == null)
			{
				return x;
			}
			int vContentSize = x.m_vContentSize;
			int vContentSize2 = y.m_vContentSize;
			long[] vArray = x.m_vArray;
			long[] vArray2 = y.m_vArray;
			FlexibleSizeLongArray flexibleSizeLongArray = new FlexibleSizeLongArray(vContentSize + vContentSize2);
			int num = 0;
			int num2 = 0;
			int vContentSize3 = 0;
			while (num < vContentSize && num2 < vContentSize2)
			{
				long num3 = vArray[num];
				long num4 = vArray2[num2];
				if (num3 == num4)
				{
					flexibleSizeLongArray.m_vArray[vContentSize3++] = num3;
					num++;
					num2++;
				}
				else if (num3 < num4)
				{
					flexibleSizeLongArray.m_vArray[vContentSize3++] = num3;
					num++;
				}
				else
				{
					flexibleSizeLongArray.m_vArray[vContentSize3++] = num4;
					num2++;
				}
			}
			for (int i = num; i < vContentSize; i++)
			{
				flexibleSizeLongArray.m_vArray[vContentSize3++] = vArray[i];
			}
			for (int j = num2; j < vContentSize2; j++)
			{
				flexibleSizeLongArray.m_vArray[vContentSize3++] = vArray2[j];
			}
			flexibleSizeLongArray.m_vContentSize = vContentSize3;
			return flexibleSizeLongArray;
		}

		public static FlexibleSizeLongArray Merge(FlexibleSizeLongArray x, long[] ya)
		{
			if (x == null)
			{
				return new FlexibleSizeLongArray(ya);
			}
			if (ya == null)
			{
				return x;
			}
			int vContentSize = x.m_vContentSize;
			int num = ya.Length;
			long[] vArray = x.m_vArray;
			FlexibleSizeLongArray flexibleSizeLongArray = new FlexibleSizeLongArray(vContentSize + num);
			int num2 = 0;
			int num3 = 0;
			int vContentSize2 = 0;
			while (num2 < vContentSize && num3 < num)
			{
				long num4 = vArray[num2];
				long num5 = ya[num3];
				if (num4 == num5)
				{
					flexibleSizeLongArray.m_vArray[vContentSize2++] = num4;
					num2++;
					num3++;
				}
				else if (num4 < num5)
				{
					flexibleSizeLongArray.m_vArray[vContentSize2++] = num4;
					num2++;
				}
				else
				{
					flexibleSizeLongArray.m_vArray[vContentSize2++] = num5;
					num3++;
				}
			}
			for (int i = num2; i < vContentSize; i++)
			{
				flexibleSizeLongArray.m_vArray[vContentSize2++] = vArray[i];
			}
			for (int j = num3; j < num; j++)
			{
				flexibleSizeLongArray.m_vArray[vContentSize2++] = ya[j];
			}
			flexibleSizeLongArray.m_vContentSize = vContentSize2;
			return flexibleSizeLongArray;
		}

		public static FlexibleSizeLongArray Insert(FlexibleSizeLongArray x, long yv)
		{
			FlexibleSizeLongArray flexibleSizeLongArray;
			if (x == null)
			{
				flexibleSizeLongArray = new FlexibleSizeLongArray(8);
				flexibleSizeLongArray.m_vArray[0] = yv;
				flexibleSizeLongArray.m_vContentSize = 1;
				return flexibleSizeLongArray;
			}
			long[] vArray = x.m_vArray;
			int vContentSize = x.m_vContentSize;
			int num;
			if (vContentSize == 0 || yv > vArray[vContentSize - 1])
			{
				num = vContentSize;
			}
			else if (yv < vArray[0])
			{
				num = 0;
			}
			else
			{
				num = Array.BinarySearch(vArray, 0, vContentSize, yv);
				if (num >= 0)
				{
					return x;
				}
				num = ~num;
			}
			int num2 = x.m_vArray.Length;
			long[] array;
			if (num2 > x.m_vContentSize)
			{
				flexibleSizeLongArray = x;
				array = vArray;
			}
			else
			{
				flexibleSizeLongArray = new FlexibleSizeLongArray(num2 + 8);
				array = flexibleSizeLongArray.m_vArray;
				for (int i = 0; i < num; i++)
				{
					array[i] = vArray[i];
				}
			}
			for (int num3 = x.m_vContentSize; num3 > num; num3--)
			{
				array[num3] = vArray[num3 - 1];
			}
			flexibleSizeLongArray.m_vArray[num] = yv;
			flexibleSizeLongArray.m_vContentSize = vContentSize + 1;
			return flexibleSizeLongArray;
		}

		public static FlexibleSizeLongArray Append(FlexibleSizeLongArray x, long yv)
		{
			FlexibleSizeLongArray flexibleSizeLongArray;
			if (x == null)
			{
				flexibleSizeLongArray = new FlexibleSizeLongArray(8);
				flexibleSizeLongArray.m_vArray[0] = yv;
				flexibleSizeLongArray.m_vContentSize = 1;
				return flexibleSizeLongArray;
			}
			int num = x.m_vArray.Length;
			if (num > x.m_vContentSize)
			{
				flexibleSizeLongArray = x;
			}
			else
			{
				flexibleSizeLongArray = new FlexibleSizeLongArray(num + 8);
				x.m_vArray.CopyTo(flexibleSizeLongArray.m_vArray, 0);
			}
			flexibleSizeLongArray.m_vArray[x.m_vContentSize] = yv;
			flexibleSizeLongArray.m_vContentSize = x.m_vContentSize + 1;
			return flexibleSizeLongArray;
		}

		public static FlexibleSizeLongArray Append(FlexibleSizeLongArray x, long[] y, int yStart, int yEnd, long mask)
		{
			int num = yEnd - yStart;
			if (y == null || num <= 0)
			{
				return x;
			}
			FlexibleSizeLongArray flexibleSizeLongArray;
			long[] vArray;
			if (x == null)
			{
				flexibleSizeLongArray = new FlexibleSizeLongArray(num + 8);
				vArray = flexibleSizeLongArray.m_vArray;
				int i = yStart;
				int num2 = 0;
				for (; i < yEnd; i++)
				{
					vArray[num2++] = mask | (y[i] & 0xFFFFFFFFu);
				}
				flexibleSizeLongArray.m_vContentSize = num;
				return flexibleSizeLongArray;
			}
			if (y == null)
			{
				return x;
			}
			int num3 = x.m_vArray.Length;
			int vContentSize = x.m_vContentSize;
			if (num3 > vContentSize + num)
			{
				flexibleSizeLongArray = x;
				vArray = x.m_vArray;
			}
			else
			{
				flexibleSizeLongArray = new FlexibleSizeLongArray(vContentSize + num + 8);
				vArray = flexibleSizeLongArray.m_vArray;
				x.m_vArray.CopyTo(vArray, 0);
			}
			int j = yStart;
			int num4 = vContentSize;
			for (; j < yEnd; j++)
			{
				vArray[num4++] = mask | (y[j] & 0xFFFFFFFFu);
			}
			flexibleSizeLongArray.m_vContentSize = vContentSize + num;
			return flexibleSizeLongArray;
		}
	}
}
